<? if ($c = stack('name')) {

	$s = component_settings($c);

	ob_start(); ?><script type="text/javascript">
	
	Date.prototype.toXMLDate = function() {
		var t, m = ((t = this.getMonth() + 1) < 10) ? ("0" + t) : "" + t, d = ((t = this.getDate()) < 10) ? ("0" + t) : "" + t;
		return this.getFullYear() + "-" + m + "-" + d;
	}

	Date.prototype.toSimpleDate = function() {
		var t, m = ((t = this.getMonth() + 1) < 10) ? ("0" + t) : "" + t, d = ((t = this.getDate()) < 10) ? ("0" + t) : "" + t;
		return d + "." + m + "." + this.getFullYear();
	}
	
	jQuery(function($) {
						 
		$.ajax({dataType:'xml', type:'get', url:"http://xml.weather.co.ua/1.2/forecast/<?=$s['city_id']?>?dayf=2&lang=<?=context('lang')?>&userid=<?=str_replace('.', '_', $_SERVER['HTTP_HOST'])?>",
			success:function(data){
				var w = $(data.responseText), city = w.find("city > name:first").text(), h = [],
				current = w.find("current"), cur_t = current.find("t").text(), cur_icon = current.find("pict").text(),
				forecast = w.find("day"), tomorrow_str = new Date((new Date()).getTime() + 86400000).toXMLDate(),
				tomorrow = w.find("day[date=" + tomorrow_str + "][hour=15]"), 
				to_tmin = tomorrow.find("t min").text(), to_tmax = tomorrow.find("t max").text(), to_icon = tomorrow.find("pict").text();

				h.push("<h3><?=$s['weather']?></h3>");
				h.push("<table>");
				h.push('<thead><tr><td colspan="2">' + city + " " + (new Date()).toSimpleDate() + '</td></tr></thead>');
				h.push("<tbody><tr>");
				h.push("<td><?=$s['today']?> <strong>" + cur_t + '</strong><img src="<?=$s['icon_path']?>' + cur_icon + '"></td>');
				h.push("<td><?=$s['tomorrow']?> <strong>" + to_tmin + '</strong> - <strong>' + to_tmax + '</strong><img src="<?=$s['icon_path']?>' + to_icon + '"></td>');
				h.push("</tr></tbody></table>");
				
				$("#cpn_<?=$c?>_weather").html(h.join(''));
			}
			
		});
		
	});
	
	</script><? $SCRIPT[] = ob_get_clean();


	?><div id="cpn_<?=$c?>_weather" class="weather"></div><?

	unstack();
} ?>